"""
@name : 07.用类实现装饰器
@author : wenyao
@projectname: xsfh
"""

#基于类实现装饰器
#callable
#让类实现__call__函数

# class A:
#     def __init__(self, func):
#         self.func = func
#     def __call__(self, *args, **kwargs):
#         print("this is call.....")
#         self.func(*args, **kwargs)
#
# @A     #func1 = A(func1)  #实例化
# def func1():
#     print("i am func1.....")
#
# func1()  #把对象当作函数去调用，自动执行魔术方法__call__

class A:
    def __init__(self,name):
        self.name = name

    def __call__(self, func):
        print("i am call......")
        # return self.func(*args, **kwargs)
        def deco(*args, **kwargs):
            print("i am deco......")
            print(self.name)
            result = func(*args, **kwargs)
            return result
        return deco

@A("name")
# deco = A("name")
# func1 = deco(func1)
def func1():
    print("i am func1......")
    return "xxxxxx"

print(func1())


